﻿using BW.Rabbit.ErrorCode;
using BW.Rabbit.Read.API.Applications.Commands.GoodsInfoCommands;
using BW.Rabbit.Read.API.Dto;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.Rabbit.Read.API.Controllers
{
    /// <summary>
    /// API控制器 - 读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MassageController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<MassageController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public MassageController(ILogger<MassageController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]//特性
        public async Task<APIResult<APIPaging<GoodInfosDto>>> GetGoodsInfo([FromQuery]GoodsInfoQueryCommands request)
        {
            try
            {
                logger.LogInformation("调用一下测试数据");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("查询数据失败" + ex.Message);
                throw;
            }
        }
    }
}
